package com.example.distributesession.config;

import com.alibaba.fastjson.JSONObject;
import com.example.distributesession.controller.vo.ResultVO;
import com.example.distributesession.util.JwtUtil;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class JwtFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("执行过滤器");
        String token = ((HttpServletRequest) request).getHeader("token");
        if (JwtUtil.verifyJWT(token)) {
            chain.doFilter(request, response);
        } else {
            ResultVO resultVO = new ResultVO(1, "fliter jwt verify fail");
            response.getWriter().write(JSONObject.toJSONString(resultVO));
        }
    }
}